<template>
  <lab-view :element="element" :model-data="modelData" show-view></lab-view>
</template>

<script>
export default {
  name: "ViewContainer",
  provide(){
    return {
      loadView: this.loadView
    }
  },
  props: {
    element: {
      type: Object,
      default: function () {
        return {}
      }
    },
    modelData: {
      type: Object,
      default: function () {
        return {}
      }
    }
  },
  methods: {
    loadView(ele, data) {
      return new Promise(resolve => {
        const { callCmd } = ele.props
        if (callCmd) {
          this.$get('/view/load/' + callCmd)
              .then(res => {
                this.$resultMsg(this, res, '视图加载异常', true)
                if (res.code === 200) {
                  ele.elements.splice(0, ele.elements.length)
                  const { element } = res.data
                  this.$Util.copyAttr(element, ele, null, this)
                }
                resolve({ code: 200 })
              })
        } else {
          resolve({ code: 200 })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
